package com.kaifamiao.demo.d0721;

import java.util.Arrays;

public class Demo06 {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};

        int index = 2;

        int num = 9;

        // 先将原来的数组内容复制到新数组
        int[] newArr = Arrays.copyOf(arr, arr.length + 1);

        // 移动前 1, 2, 3, 4, 5, 0
        // 从 下标 2 开始往后移 一位
        System.arraycopy(newArr, index, newArr, index + 1, newArr.length - index - 1);

        // 移动后 1, 2, 3, 3, 4, 5
        newArr[index] = num;

        for (int i = 0; i < newArr.length; i ++){
            System.out.println(newArr[i]);
        }




    }
}
